//分类添加
;(function ($, global) {
  let _token = $('input[name=_token]').eq(0).val()
  let $form = $('#category-form')
  let $submit = $form.find('button.submit')

  let verify = {}

  let fnInitAddReq = function () {
    return new FormData($form[0])
  }

  let fnAddAjax = function (data) {
    fnUploadAjax('POST', 'category/add', data, 'json', fnCommonAddSuccess, fnCommonAddError)
  }

  let fnTrigger = function () {
    $submit.click(function () {
      let req = fnInitAddReq($form)
      if (reqVerify(req, verify)) {
        //   fnBtnDisable($(this))
        fnLoading()
        fnAddAjax(req)
      }
    })
  }

  fnTrigger()
}(jQuery, window))

//分类修改
;(function ($, global) {
  let _token = $('input[name=_token]').eq(0).val()
  let $form = $('#category-edit-form')
  let $submit = $form.find('button.submit')

  let verify = {}

  let fnInitReq = function () {
    return new FormData($form[0])
  }

  let fnEditAjax = function (data) {
    fnUploadAjax('POST', 'category/edit?id=' + data.get('id'), data, 'json', fnCommonEditSuccess, fnCommonEditError)
  // api_ajax('POST', 'usermenu/edit?id=' + data.id, data, 'json', suc, err)
  }

  let fnTrigger = function () {
    $submit.click(function () {
      let req = fnInitReq($form)
      if (reqVerify(req, verify)) {
        //   fnBtnDisable($(this))
        fnLoading()
        fnEditAjax(req)
      }
    })
  }

  fnTrigger()
}(jQuery, window))
